<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of Brand_Category
 *
 * @author Samuel Pulta
 */
class Brand_Category extends Ebrochure {
    //put your code here
    
    //public $unique_id;
    public $brand_title;
    public $brand_category;
    public $role_id;
    public $department_id;
    public $is_active;
    
    public function __construct($db, $id) {
        $this->init($db, $id);
    }
    
    public function init($db, $id){
        $this->db = $db;
        $this->tblname = TB_BRAND_CATEGORY;
        $this->id = $id;
        
        if($id){
            $result = $this->db->query("SELECT * FROM " . $this->db->tbl_name($this->tblname) . " WHERE id = {$this->db->escape($id)}", "row");

            $this->id = $result['id'];
            $this->brand_title = $result['brand_title'];
            $this->brand_category = $result['brand_category'];
            $this->role_id = $result['role_id'];
            $this->department_id = $result['department_id'];	
            $this->is_active = $result['is_active']; 
        }
    }
    
    public function query_array(){
        $result = $this->db->query("SELECT * FROM " . $this->db->tbl_name($this->tblname) . " WHERE id = {$this->db->escape($this->id)} AND is_active={$this->db->escape(1)}", "array");
        return  $result;
    }
    
    public function query_numrows(){
        $result = $this->db->query("SELECT * FROM " . $this->db->tbl_name($this->tblname), "numrows");
        return $result;
    }
    
    public function save() {
        $insert_array = array(	
            "brand_title"               =>  $this->brand_title,
            "brand_category"            =>  $this->brand_category,
            "role_id"                   =>  $this->role_id,
            "department_id"             =>  $this->department_id,
            "is_active"                 =>  $this->is_active

        );
    
        $insert_id = $this->db->insert($this->db->tbl_name($this->tblname), $insert_array);
    
        $this->id = $insert_id;
    }
    //
    public function update() {
        $update_array = array(
            "brand_title"               =>  $this->brand_title,
            "brand_category"            =>  $this->brand_category,
            "role_id"                   =>  $this->role_id,
            "department_id"             =>  $this->department_id,
            "is_active"                 =>  $this->is_active
        );
    
        $condition_array = array("id" => $this->id);
    
        $this->db->update($this->db->tbl_name($this->tblname), $update_array, $condition_array);
    }
}

?>
